<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			var arr = [1, 2, 3, 4, 5, 6];
			
			// 第一种方法用splice重写数组原型上的unshift方法
			Array.prototype.myUnshift = function(){
				var pos = 0;
				for (var i = 0; i < arguments.length; i++){
					this.splice(pos, 0, arguments[i]);
					pos++;
				}
				return this.length;
			}
			
			// 用concat重写unshift方法
			Array.prototype.myUnshift = function(){
				var argArr = Array.prototype.slice.call(arguments);
				var newArr = argArr.concat(this);
				return newArr;
			}
			
			var newArr = arr.myUnshift('a', 'b');
			console.log(newArr);
		</script>
	</body>
</html>
